package org.action;


import java.util.Map;

import org.dao.DIDao;
import org.model.Dlb;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {

	/**
	 */
	//新增一个action变量loginJsp_dlb 这个变量待会会再后面login.jsp页面中使用
	//定义两个action变量,生成getter and setter 函数，当执行网页提交时将自动调用
	private Dlb loginJsp_dlb;
	private Dlb mainJsp_user;
	//定义一个依赖注入接口属性，生成getter 和setter 函数，当生成bean对象生成loginAction时将自动调用
	private DIDao dlDao;
	
	
	public DIDao getDlDao() {
		return dlDao;
	}
	public void setDlDao(DIDao dlDao) {
		this.dlDao = dlDao;
	}
	public Dlb getMainJsp_user() {
		return mainJsp_user;
	}
	public void setMainJsp_user(Dlb mainJsp_user) {
		this.mainJsp_user = mainJsp_user;
	}
	public Dlb getLoginJsp_dlb() {
		return loginJsp_dlb;
	}
	public void setLoginJsp_dlb(Dlb loginJsp_Dlb) {
		loginJsp_dlb = loginJsp_Dlb;
	}
	//执行login.action 时候生成execute方法
	public String execute() throws Exception{
		
		Dlb user = dlDao.validate(loginJsp_dlb.getXh(), loginJsp_dlb.getKl());
		if(user!=null){
			mainJsp_user = user;
			Map session = ActionContext.getContext().getSession();
			session.put("dlUser", user);
			return "success";
		}else
			return "error";
		
		/*ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		DIDao dlDao = (DIDao) context.getBean("dlDaoImp");
		Dlb user = dlDao.validate(loginJsp_dlb.getXh(), loginJsp_dlb.getKl());
		if(user!=null){
			mainJsp_user = user;
			Map session = ActionContext.getContext().getSession();
			session.put("dlUser", user);
			return "success";
		}else
			return "error";
		*/
	}
	
	
	
	/*public String execute(){
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		DIDao dlDao = (DIDao) context.getBean("dlDaoImp");
		Dlb user = dlDao.validate(loginJsp_dlb.getXh(), loginJsp_dlb.getKl());
		if(user!=null){
			//此处将设置action变量和session变量
			mainJsp_user = user;
			//将登录用户对象放置jsp的session对象中
			Map session = ActionContext.getContext().getSession();
			return "success";
		}else 
			return "error";
	}*/
	
}
